using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 审计规则配置实体
    /// </summary>
    [Table("audit_rules")]
    public class AuditRule : ITenantEntity
    {
        [Key]
        public Guid Id { get; set; }
        
        [Required]
        [MaxLength(100)]
        public string TenantId { get; set; } = string.Empty;
        
        /// <summary>
        /// 规则名称
        /// </summary>
        [Required]
        [MaxLength(255)]
        public string Name { get; set; } = string.Empty;
        
        /// <summary>
        /// 规则描述
        /// </summary>
        [MaxLength(1000)]
        public string? Description { get; set; }
        
        /// <summary>
        /// 资源类型模式 (支持通配符)
        /// </summary>
        [Required]
        [MaxLength(255)]
        public string ResourceTypePattern { get; set; } = string.Empty;
        
        /// <summary>
        /// 操作模式 (支持通配符)
        /// </summary>
        [Required]
        [MaxLength(255)]
        public string ActionPattern { get; set; } = string.Empty;
        
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsEnabled { get; set; } = true;
        
        /// <summary>
        /// 是否记录操作前数据
        /// </summary>
        public bool LogOldValues { get; set; } = true;
        
        /// <summary>
        /// 是否记录操作后数据
        /// </summary>
        public bool LogNewValues { get; set; } = true;
        
        /// <summary>
        /// 风险级别
        /// </summary>
        [MaxLength(20)]
        public string RiskLevel { get; set; } = "Low";
        
        /// <summary>
        /// 保留天数 (0表示永久保留)
        /// </summary>
        public int RetentionDays { get; set; } = 365;
        
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }
        
        /// <summary>
        /// 创建用户ID
        /// </summary>
        [MaxLength(100)]
        public string? CreatedBy { get; set; }
        
        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? UpdatedAt { get; set; }
        
        /// <summary>
        /// 最后修改用户ID
        /// </summary>
        [MaxLength(100)]
        public string? UpdatedBy { get; set; }
    }

    /// <summary>
    /// 审计报告实体
    /// </summary>
    [Table("audit_reports")]
    public class AuditReport : ITenantEntity
    {
        [Key]
        public Guid Id { get; set; }
        
        [Required]
        [MaxLength(100)]
        public string TenantId { get; set; } = string.Empty;
        
        /// <summary>
        /// 报告名称
        /// </summary>
        [Required]
        [MaxLength(255)]
        public string Name { get; set; } = string.Empty;
        
        /// <summary>
        /// 报告类型 (Summary, Detailed, Compliance, etc.)
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string Type { get; set; } = string.Empty;
        
        /// <summary>
        /// 报告描述
        /// </summary>
        [MaxLength(1000)]
        public string? Description { get; set; }
        
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime StartDate { get; set; }
        
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime EndDate { get; set; }
        
        /// <summary>
        /// 筛选条件 (JSON格式)
        /// </summary>
        public string? FilterCriteria { get; set; }
        
        /// <summary>
        /// 报告状态 (Generating, Ready, Failed)
        /// </summary>
        [Required]
        [MaxLength(20)]
        public string Status { get; set; } = "Generating";
        
        /// <summary>
        /// 文件路径
        /// </summary>
        [MaxLength(500)]
        public string? FilePath { get; set; }
        
        /// <summary>
        /// 文件大小 (字节)
        /// </summary>
        public long? FileSize { get; set; }
        
        /// <summary>
        /// 格式 (PDF, Excel, CSV)
        /// </summary>
        [MaxLength(20)]
        public string Format { get; set; } = "PDF";
        
        /// <summary>
        /// 生成时间
        /// </summary>
        public DateTime CreatedAt { get; set; }
        
        /// <summary>
        /// 生成用户ID
        /// </summary>
        [MaxLength(100)]
        public string? CreatedBy { get; set; }
        
        /// <summary>
        /// 完成时间
        /// </summary>
        public DateTime? CompletedAt { get; set; }
        
        /// <summary>
        /// 错误信息
        /// </summary>
        public string? ErrorMessage { get; set; }
        
        /// <summary>
        /// 下载次数
        /// </summary>
        public int DownloadCount { get; set; } = 0;
        
        /// <summary>
        /// 最后下载时间
        /// </summary>
        public DateTime? LastDownloadedAt { get; set; }
        
        /// <summary>
        /// 过期时间
        /// </summary>
        public DateTime? ExpiresAt { get; set; }
    }

    /// <summary>
    /// 审计配置实体
    /// </summary>
    [Table("audit_configurations")]
    public class AuditConfiguration : ITenantEntity
    {
        [Key]
        public Guid Id { get; set; }
        
        [Required]
        [MaxLength(100)]
        public string TenantId { get; set; } = string.Empty;
        
        /// <summary>
        /// 是否启用审计
        /// </summary>
        public bool IsEnabled { get; set; } = true;
        
        /// <summary>
        /// 默认保留天数
        /// </summary>
        public int DefaultRetentionDays { get; set; } = 365;
        
        /// <summary>
        /// 是否启用实时通知
        /// </summary>
        public bool EnableRealTimeNotification { get; set; } = false;
        
        /// <summary>
        /// 高风险操作通知邮箱 (JSON数组)
        /// </summary>
        public string? HighRiskNotificationEmails { get; set; }
        
        /// <summary>
        /// 是否启用数据脱敏
        /// </summary>
        public bool EnableDataMasking { get; set; } = true;
        
        /// <summary>
        /// 脱敏规则 (JSON格式)
        /// </summary>
        public string? MaskingRules { get; set; }
        
        /// <summary>
        /// 是否启用性能监控
        /// </summary>
        public bool EnablePerformanceMonitoring { get; set; } = true;
        
        /// <summary>
        /// 性能阈值 (毫秒)
        /// </summary>
        public int PerformanceThreshold { get; set; } = 1000;
        
        /// <summary>
        /// 最大批处理大小
        /// </summary>
        public int MaxBatchSize { get; set; } = 1000;
        
        /// <summary>
        /// 批处理间隔 (秒)
        /// </summary>
        public int BatchInterval { get; set; } = 10;
        
        /// <summary>
        /// 是否启用IP白名单
        /// </summary>
        public bool EnableIpWhitelist { get; set; } = false;
        
        /// <summary>
        /// IP白名单 (JSON数组)
        /// </summary>
        public string? IpWhitelist { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }
        
        /// <summary>
        /// 创建用户ID
        /// </summary>
        [MaxLength(100)]
        public string? CreatedBy { get; set; }
        
        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? UpdatedAt { get; set; }
        
        /// <summary>
        /// 最后修改用户ID
        /// </summary>
        [MaxLength(100)]
        public string? UpdatedBy { get; set; }
    }
}
